package com.bootdo.blog.dao;

import com.bootdo.blog.domain.PackagingDO;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
/**
 * 
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2021-03-07 10:38:32
 */
@Mapper
public interface PackagingMapper {

	@Select("select `package_id`, `product_name`, `product_code`, `specification`, `trace_code`, `package_number`, `package_time` from tb_packaging where package_id = #{id}")
	PackagingDO get(Integer packageId);
	
	@Select("<script>" +
	"select * from tb_packaging " + 
			"<where>" + 
		  		  "<if test=\"packageId != null and packageId != ''\">"+ "and package_id = #{packageId} " + "</if>" + 
		  		  "<if test=\"productName != null and productName != ''\">"+ "and product_name = #{productName} " + "</if>" + 
		  		  "<if test=\"productCode != null and productCode != ''\">"+ "and product_code = #{productCode} " + "</if>" + 
		  		  "<if test=\"specification != null and specification != ''\">"+ "and specification = #{specification} " + "</if>" + 
		  		  "<if test=\"traceCode != null and traceCode != ''\">"+ "and trace_code = #{traceCode} " + "</if>" + 
		  		  "<if test=\"packageNumber != null and packageNumber != ''\">"+ "and package_number = #{packageNumber} " + "</if>" + 
		  		  "<if test=\"packageTime != null and packageTime != ''\">"+ "and package_time = #{packageTime} " + "</if>" + 
		  			"</where>"+ 
			" <choose>" + 
	            "<when test=\"sort != null and sort.trim() != ''\">" + 
	                "order by ${sort} ${order}" + 
	            "</when>" + 
				"<otherwise>" + 
	                "order by package_id desc" + 
				"</otherwise>" + 
	        "</choose>"+
			"<if test=\"offset != null and limit != null\">"+
			"limit #{offset}, #{limit}" + 
			"</if>"+
			"</script>")
	List<PackagingDO> list(Map<String, Object> map);
	
	@Select("<script>" +
	"select count(*) from tb_packaging " + 
			"<where>" + 
		  		  "<if test=\"packageId != null and packageId != ''\">"+ "and package_id = #{packageId} " + "</if>" + 
		  		  "<if test=\"productName != null and productName != ''\">"+ "and product_name = #{productName} " + "</if>" + 
		  		  "<if test=\"productCode != null and productCode != ''\">"+ "and product_code = #{productCode} " + "</if>" + 
		  		  "<if test=\"specification != null and specification != ''\">"+ "and specification = #{specification} " + "</if>" + 
		  		  "<if test=\"traceCode != null and traceCode != ''\">"+ "and trace_code = #{traceCode} " + "</if>" + 
		  		  "<if test=\"packageNumber != null and packageNumber != ''\">"+ "and package_number = #{packageNumber} " + "</if>" + 
		  		  "<if test=\"packageTime != null and packageTime != ''\">"+ "and package_time = #{packageTime} " + "</if>" + 
		  			"</where>"+ 
			"</script>")
	int count(Map<String, Object> map);
	
	@Insert("insert into tb_packaging (`product_name`, `product_code`, `specification`, `trace_code`, `package_number`, `package_time`)"
	+ "values (#{productName}, #{productCode}, #{specification}, #{traceCode}, #{packageNumber}, #{packageTime})")
	int save(PackagingDO packaging);
	
	@Update("<script>"+ 
			"update tb_packaging " + 
					"<set>" + 
		            "<if test=\"packageId != null\">`package_id` = #{packageId}, </if>" + 
                    "<if test=\"productName != null\">`product_name` = #{productName}, </if>" + 
                    "<if test=\"productCode != null\">`product_code` = #{productCode}, </if>" + 
                    "<if test=\"specification != null\">`specification` = #{specification}, </if>" + 
                    "<if test=\"traceCode != null\">`trace_code` = #{traceCode}, </if>" + 
                    "<if test=\"packageNumber != null\">`package_number` = #{packageNumber}, </if>" + 
                    "<if test=\"packageTime != null\">`package_time` = #{packageTime}, </if>" + 
          					"</set>" + 
					"where package_id = #{packageId}"+
			"</script>")
	int update(PackagingDO packaging);
	
	@Delete("delete from tb_packaging where package_id =#{packageId}")
	int remove(Integer package_id);
	
	@Delete("<script>"+ 
			"delete from tb_packaging where package_id in " + 
					"<foreach item=\"packageId\" collection=\"array\" open=\"(\" separator=\",\" close=\")\">" + 
						"#{packageId}" + 
					"</foreach>"+
			"</script>")
	int batchRemove(Integer[] packageIds);
}
